package com.yadang.service.impl;

import com.yadang.commonpent.SaleDao;
import com.yadang.commonpent.UserDao;
import com.yadang.service.RegistrationService;
import com.yadang.service.entity.SalesRes;
import com.yadang.service.entity.User;
import com.yadang.service.utils.FindUtils;

import javax.xml.bind.ValidationException;

/**
 * @author: 亚当
 * @date: 2023年02月15日 21:49
 * @package: com.yadang.service.impl
 * @Description: TODO
 */
public class RegistrationServiceImpl implements RegistrationService {

    SaleDao saleDao = new SaleDao();
    User userDao = new UserDao();
    @Override
    public User register(String name, String phone) throws Exception {
        // 参数校验
        if (name == null || name.length() == 0){
            throw new ValidationException("number 不能为空");
        }
        if (phone == null || phone.length() == 0){
            throw new ValidationException("phone 格式错误");
        }
        // 获取手机归属地编号和运营商编号
        String areaCode = FindUtils.getAreaCode(phone);
        String operatorCode = FindUtils.getOperatorCode(phone);

        User user = null;
        SalesRes rep = saleDao.findRep(areaCode,operatorCode);
        userDao.save(name,phone);
        return user;
    }
}
